package com.greenold.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.enums.BusinessType;
import com.greenold.service.domain.CareLevel;
import com.greenold.service.service.ICareLevelService;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.common.core.page.TableDataInfo;

/**
 * 护理等级Controller
 *
 * @author YueYang
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/service/level")
public class CareLevelController extends BaseController {
    @Autowired
    private ICareLevelService careLevelService;

    /**
     * 查询护理等级列表
     */
    @PreAuthorize("@ss.hasPermi('service:level:list')")
    @GetMapping("/list")
    public TableDataInfo list(CareLevel careLevel) {
        startPage();
        List<CareLevel> list = careLevelService.selectCareLevelList(careLevel);
        return getDataTable(list);
    }


    /**
     * 根据id 获取护理等级详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:level:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(careLevelService.selectCareLevelById(id));
    }

    /**
     * 新增护理等级
     */
    @PreAuthorize("@ss.hasPermi('service:level:add')")
    @Log(title = "护理等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CareLevel careLevel) {
        return toAjax(careLevelService.insertCareLevel(careLevel));
    }

    /**
     * 修改护理等级
     */
    @PreAuthorize("@ss.hasPermi('service:level:edit')")
    @Log(title = "护理等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CareLevel careLevel) {
        return toAjax(careLevelService.updateCareLevel(careLevel));
    }

    /**
     * 删除护理等级
     */
    @PreAuthorize("@ss.hasPermi('service:level:remove')")
    @Log(title = "护理等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(careLevelService.deleteCareLevelByIds(ids));
    }


    /**
     * 启用禁用护理等级
     */
    @PreAuthorize("@ss.hasPermi('service:level:stop')")
    @Log(title = "护理等级", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus/{id}")
    public AjaxResult changeStatus(@PathVariable Integer id, @RequestParam String status) {
        return toAjax(careLevelService.changeStatus(id, status));
    }

    /**
     * 查询老人表获取绑定的所有护理等级id
     */
//    @PreAuthorize("@ss.hasPermi('service:level:query')")
    @GetMapping("/bindIds")
    public AjaxResult getBindCareLevelIds() {
        return success(careLevelService.getBindCareLevelIds());
    }


}
